package org.example.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig {
    @Bean
    public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
        http
                .authorizeHttpRequests((authorize) -> authorize


//                        .requestMatchers("/teacher/**").hasRole("TEACHER")
                        .requestMatchers("/teacher/delete").hasAuthority("teacher:delete")
                        .anyRequest().authenticated() // 任何访问均需要认证
                )
                .formLogin(form -> form
                        // 允许所有用户访问登录页面
                        .permitAll()
                );
        return http.build();
    }
}
